package com.yuan.thead;

import java.util.concurrent.locks.Lock;

public class VolatileTest {

    //在没有  volatile 的情况下  线程结束不会被输出
    private volatile static boolean running = true;

    public static class T1 extends Thread {
        public void run() {
            while (running) {

            }
            System.out.println("线程结束" + running);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new T1().start();
        Thread.sleep(10);
        running = false;
        while (!running) {

        }
    }


}





